<template>
  <div>
    <div id="box">
      <div class="container">
        <div class="login-wrapper">
          <div class="header">工作辛苦了</div>
          <div class="form-wrapper">
            <input type="text" name="username" v-model="account.accountName" placeholder="请输入用户名" class="input-item">
            <input type="password" name="password" v-model="account.accountPass" placeholder="请输入密码" class="input-item">
            <button @click="login" class="btn">立即登录</button>
          </div>
          <div class="msg">
            <a href="#/userLogin">>>返回用户登录</a>
          </div>
        </div>
        <div class="fd text">&copy;版本所有&nbsp;&nbsp;108期&nbsp;&nbsp;|&nbsp;&nbsp;<a id="textDown" href="https://www.woniuxy.com">蜗牛学苑</a></div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "employeeLogin",
    data() {
      return {
        account: {
          accountName: "",
          accountPass: ""
        },
        flag: true,
      }
    },
    methods: {
      login() {
        let username = this.account.accountName;
        let password = this.account.accountPass;
        if (password == null || password === "") {
          alert("请输入密码!");
        } else {
          const self = this; // 存储外部上下文的this
          this.$http.post("/permissions/account/login", {
            accountId: username,
            passWord: password
          }).then(resp => {
            console.log(resp.data.message);
            if (resp.data.code == 200) {
              console.log(resp.data.data)
              // 获取后端返回的DTO对象
              let accountDto = resp.data.data;
              // 获取用户角色
              let role = accountDto.role;
              if (role === 1) {
                window.location.href = "https://www.baidu.com";
              } else if (role === 2){
                this.$router.push("/employeeOrder");
              } else if (role === 3) {
                this.$router.push("/assEmploye");
              } else if (role === 4) {
                this.$router.push("/admin");
              } else {
                // 用户角色不匹配，显示错误消息
                this.$message.error("用户角色错误");
              }
            } else {
              this.$message.error(resp.data.message);
              this.account.accountName = "";
              this.account.accountPass = "";
            }
          });
        }
      }
    }
  }
</script>
<style >
  * {
    margin: 0;
    padding: 0;
  }

  html {
    height: 100%;
  }

  body {
    height: 100%;
  }

  .container {
    height: 100%;
    background-image: url(../../static/11.jpg)
  }

  .login-wrapper {
    margin-left: 400px;
    background-color: rgba(255, 255, 255, 0.9);
    width: 358px;
    height: 588px;
    border-radius: 15px;
    padding: 0 50px;
    position: relative;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }

  .header {
    font-family: "arial rounded mt bold";
    font-size: 30px;
    font-weight: bold;
    text-align: center;
    line-height: 200px;
  }

  .input-item {
    display: block;
    width: 100%;
    margin-bottom: 20px;
    border: 0;
    padding: 10px;
    border-bottom: 1px solid rgb(128, 125, 125);
    font-size: 15px;
    outline: none;
  }

  .input-item:placeholder {
    text-transform: uppercase;
  }

  .btn {
    text-align: center;
    padding: 10px;
    width: 100%;
    margin-top: 40px;
    background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
    color: #fff;
  }

  .msg {
    text-align: center;
    line-height: 88px;
  }

  a {
    text-decoration-line: none;
    color: #abc1ee;
  }

  #box {
    height: 906px;
    weight: 2560px;
  }

  .text {
    margin-left: 720px;
    margin-top: 200px;
  }

  #textDown {
    font-family: '仿宋', sans-serif;
    color: #ff69b4;
  }


  .cl::after {
    content: '';
    display: block;
    clear: both;
    /*该代码段先将一个空字符串插入引用cl的块级元素 并将这个空字符串转为
      	块级元素 该块级元素会占据父元素的所有宽度 clear:both 将浮动在上面的元素展示在 空字符串下面
      	该伪类是class 类型 选择器
      	*/
  }

  .fdl {
    float: left;
    border: none;
  }

  .fdr {
    float: right;
    border: none;
  }

  .fd {
    float: left;
    border: none;
  }
</style>
